import axios from "axios";
import config from "../config";

const request = axios.create({
	headers: {
		Authorization: config.OLD.TOKEN
	},
	timeout: 1000 * 60 * 30,
	baseURL: config.OLD.SERVER_URL
});

/** 获取设备信息信息 */
export const getDeviceInfoList = (name?: string) => {
	return request({
		url: `/device/page`,
		method: "GET",
		params: {
			page: 1,
			limit: 9999,
			name
		}
	});
};

/** 根据设备id获取设备关联的排期数据 */
export const getDevicePlanLog = (deviceId: string) => {
	return request({
		url: `/planLog/page`,
		method: "GET",
		params: {
			page: 1,
			limit: 9999,
			deviceId
		}
	});
};

/** 获取排期信息 */
export const getPlanList = (name?: string) => {
	return request({
		url: `/plan/page`,
		method: "GET",
		params: {
			page: 1,
			limit: 9999,
			name
		}
	});
};

/** 获取排期详细信息 */
export const getPlanDetail = (id: string) => {
	return request({
		url: `/plan/get`,
		method: "GET",
		params: {
			id
		}
	});
};

/** 根据节目单id获取素材信息 */
export const getProgramMaterial = (id: string) => {
	return request({
		url: `/program/material/${id}`,
		method: "GET"
	});
};

/** 根据节目单id获取素材信息 */
export const getMaterialPage = (params?: {
	/** 文件名称 */
	fileName?: string;
	/**
	 * 文件类型
	 * - 1: 图片
	 * - 2: 文档(pdf)
	 * - 3: 音频
	 * - 4: 视频
	 */
	fileType?: "1" | "2" | "3" | "4";
}) => {
	return request({
		url: `/material/page`,
		method: "GET",
		params: {
			page: 1,
			limit: 9999,
			checkState: "1", // 审核通过
			...params
		}
	});
};
